package com.king.nio.filechannel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * transferFrom 快速拷贝
 *
 * @author king
 * @date 2020/12/26 22:53
 */
public class NioFileChannel04 {
    public static void main(String[] args) throws IOException {
        // 获取输入输出管道
        FileInputStream fileInputStream = new FileInputStream("e:/Java.jpg");
        FileChannel fileInputStreamChannel = fileInputStream.getChannel();

        FileOutputStream fileOutputStream = new FileOutputStream("e:/JavaCopy.jpg");
        FileChannel fileOutputStreamChannel = fileOutputStream.getChannel();

        fileOutputStreamChannel.transferFrom(fileInputStreamChannel, 0, fileInputStreamChannel.size());

        fileInputStreamChannel.close();
        fileOutputStreamChannel.close();
        fileInputStream.close();
        fileOutputStream.close();
    }
}
